home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource5 / 311_01 / itest.c < prev    next >
C/C++ Source or Header  |  1990-04-23  |  4KB  |  126 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      itest.c  v1.3  (c) 1990  Ken Harris                                 */
  5. /*                                                                          */
  6. /*                                                                          */
  7. /****************************************************************************/
  8. /*                                                                          */
  9. /*      This software is made available on an AS-IS basis. Unrestricted     */
  10. /*      use is granted provided that the copyright notice remains intact.   */
  11. /*      The author makes no warranties expressed or implied.                */
  12. /*                                                                          */
  13. /****************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include "db.h"
  17.  
  18. char     data[2040];
  19. main()
  20. {
  21.         DATA_SET ds;
  22.         int      i,j;
  23.  
  24.         memset(data,' ',2040);
  25.         printf("itest - Test ISAM file routines\n\n");
  26.         rcreate();
  27.         printf("...test file created...\n\n");
  28.  
  29.         ds = db_open("", "itest.dat");
  30.         if (db_error)
  31.         {       printf("Open Failure - %s\n", db_error_msg(db_error));
  32.                 exit(0);
  33.         }
  34.  
  35.         printf("...adding 100 records in reverse ...\n");
  36.         for (i=100; i>0; i--)
  37.         {       printf("%d\n",i);
  38.                 sprintf(data,"%05d",i);
  39.                 db_add(ds, data);
  40.                 if (db_error)
  41.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  42.                         exit(0);
  43.                 }
  44.         }
  45.         printf("...add complete...\n\n");
  46.  
  47.     printf("...read forward...\n\n");
  48.         db_read_first(ds, data);
  49.         while (!db_error)
  50.         {       printf("%5s\n",data);
  51.                 db_read_next(ds, data);
  52.         }
  53.         if (db_error != DB_END_OF_FILE)
  54.         {       printf("Read Sequential - %s\n", db_error_msg(db_error));
  55.                 exit(0);
  56.         }
  57.     printf("...read forward complete...\n\n");
  58.  
  59.     printf("...read reverse...\n\n");
  60.     db_read_last(ds, data);
  61.         while (!db_error)
  62.         {       printf("%5s\n",data);
  63.         db_read_prev(ds, data);
  64.         }
  65.         if (db_error != DB_END_OF_FILE)
  66.         {       printf("Read Sequential - %s\n", db_error_msg(db_error));
  67.                 exit(0);
  68.         }
  69.     printf("...read reverse complete...\n\n");
  70.  
  71.         printf("...find and delete...\n");
  72.         for (i=1; i<101; i++)
  73.         {       printf("%d\n",i);
  74.                 sprintf(data,"%05d",i);
  75.  
  76.                 db_find(ds, data, data, 0);
  77.                 if (db_error)
  78.                 {       printf("Find Failure - %s\n", db_error_msg(db_error));
  79.                         exit(0);
  80.                 }
  81.                 db_delete(ds);
  82.                 if (db_error)
  83.                 {       printf("Delete Failure - %s\n", db_error_msg(db_error));
  84.                         exit(0);
  85.                 }
  86.         }
  87.         printf("...find and delete complete...\n\n");
  88.  
  89.         printf("...adding 100 records (again) ...\n");
  90.         for (i=1; i<101; i++)
  91.         {       printf("%d\n",i);
  92.                 sprintf(data,"%05d",i);
  93.                 db_add(ds, data);
  94.                 if (db_error)
  95.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  96.                         exit(0);
  97.                 }
  98.         }
  99.         printf("...add complete...\n\n");
  100.  
  101.         db_close(ds);
  102.         unlink("itest.dat");
  103. }
  104.  
  105. /*
  106.  *      rcreate - create our test random file
  107.  */
  108.  
  109. rcreate()
  110. {
  111.         DATA_SET ds;
  112.  
  113.  
  114.         ds = db_create("", "itest.dat", "idx, rec=25, blk=512, key=5");
  115.         if (db_error)
  116.         {       printf("Create Failure - %s\n", db_error_msg(db_error));
  117.                 exit(0);
  118.         }
  119.  
  120.         db_close(ds);
  121.         if (db_error)
  122.         {       printf("Close Failure - %s\n", db_error_msg(db_error));
  123.                 exit(0);
  124.         }
  125. }
  126.